package com.lei.datastructure.queue;

import java.util.Random;

/**
 * @Author LeiXiaoLei
 * @Date 2022/7/19 11:04
 * @Version 1.0
 */
public class Main {
    public static void main(String[] args) {
        test01();
        int opCount = 100000;
        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        double testQueue = testQueue(arrayQueue, opCount);
        LoopQueue<Integer> loopQueue = new LoopQueue<>();
        double testLoopQueue = testQueue(loopQueue, opCount);
        ListedListQueue<Integer> listedListQueue = new ListedListQueue<>();
        double testListedListQueue= testQueue(listedListQueue, opCount);
        System.out.println("ArrayQueue: " + testQueue + "s");
        System.out.println("LoopQueue: " + testLoopQueue + "s");
        System.out.println("ListedListQueue: " + testListedListQueue + "s");
    }

    private static double testQueue(Queue<Integer> q, int opCount) {
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            q.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            q.dequeue();
        }
        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }

    private static void test01() {
        ListedListQueue<Integer> queue = new ListedListQueue<>();
        System.out.println(queue);
        for (int i = 0; i < 20; i++) {
            queue.enqueue(i);
            System.out.println(queue);
        }
        for (int i = 0; i < 16; i++) {
            queue.dequeue();
            System.out.println(queue);
        }
        System.out.println(queue);
    }
}
